package com.javasm.bootdemo.login.service.Impl;

import com.javasm.bootdemo.common.exception.JavasmException;
import com.javasm.bootdemo.common.exception.JavasmExceptionEnum;
import com.javasm.bootdemo.login.service.LoginService;
import com.javasm.bootdemo.user.dao.WebUserDao;
import com.javasm.bootdemo.user.entity.WebUser;
import com.javasm.bootdemo.user.service.WebUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@Service
public class LoginServiceImpl implements LoginService {



    @Resource
    WebUserService  userService;



    @Resource
    HttpSession session;
    @Override
    public WebUser loadByUname(String uname, String pwd) {
        //根据用户名查询信息
            WebUser webUser = userService.queryByUname(uname);
            if(webUser == null ){
                throw new JavasmException(JavasmExceptionEnum.UserNotExist);
            }

            if(!pwd.equals(webUser.getPassword())){
                throw new JavasmException(JavasmExceptionEnum.PasswordError);
            }
            //登录成功，存入session
        session.setAttribute("user",webUser);


            return webUser;
    }
}
